package com.taobao.txc.common.util;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Timer;

public class a
{
  private InputStream a;
  private InputStream b;
  private Process c;
  private static long d = 5000L;
  
  public void a(String[] paramArrayOfString, d paramd)
  {
    if (this.c != null) {
      a();
    }
    this.c = Runtime.getRuntime().exec(paramArrayOfString);
    a(paramd);
  }
  
  public void a(String paramString, d paramd)
  {
    if (this.c != null) {
      a();
    }
    this.c = Runtime.getRuntime().exec(paramString);
    a(paramd);
  }
  
  private void a(d paramd)
  {
    this.a = this.c.getInputStream();
    this.b = this.c.getErrorStream();
    if (paramd != null)
    {
      InputStream localInputStream;
      if (paramd == d.a)
      {
        localInputStream = this.a;
        this.a = null;
      }
      else
      {
        localInputStream = this.b;
        this.b = null;
      }
      if (localInputStream != null)
      {
        Thread localThread = new Thread(new b(this, localInputStream));
        localThread.start();
      }
    }
  }
  
  public String a(d paramd, long paramLong)
  {
    if (paramd == null) {
      return null;
    }
    InputStream localInputStream;
    if (paramd == d.a) {
      localInputStream = this.a;
    } else {
      localInputStream = this.b;
    }
    if (localInputStream == null) {
      return null;
    }
    boolean[] arrayOfBoolean = { false };
    InputStreamReader localInputStreamReader = new InputStreamReader(localInputStream);
    BufferedReader localBufferedReader = new BufferedReader(localInputStreamReader);
    Timer localTimer = new Timer();
    localTimer.schedule(new c(this, localTimer, arrayOfBoolean), paramLong);
    StringBuilder localStringBuilder = new StringBuilder();
    try
    {
      while (((arrayOfBoolean[0] == 0) && (localInputStream.available() == 0)) || (localInputStream.available() > 0)) {
        if (localInputStream.available() > 0)
        {
          localStringBuilder.append(localBufferedReader.readLine()).append("\n");
        }
        else
        {
          if (localInputStream.markSupported())
          {
            localInputStream.mark(1);
            if (localInputStream.read() == -1) {
              break;
            }
            localInputStream.reset();
          }
          Thread.sleep(1000L);
        }
      }
    }
    catch (Exception localException)
    {
      throw localException;
    }
    finally
    {
      localTimer.cancel();
    }
    return localStringBuilder.toString();
  }
  
  public void a()
  {
    if (this.a != null)
    {
      try
      {
        this.a.close();
      }
      catch (IOException localIOException1) {}
      this.a = null;
    }
    if (this.b != null)
    {
      try
      {
        this.b.close();
      }
      catch (IOException localIOException2) {}
      this.b = null;
    }
    if (this.c != null)
    {
      this.c.destroy();
      this.c = null;
    }
  }
}


/* Location:           C:\Users\ibm\Downloads\txc-yun-sample (1)\txc-yun-sample\lib\txc-client-2.0.72.jar
 * Qualified Name:     com.taobao.txc.common.util.a
 * JD-Core Version:    0.7.0.1
 */